package com.example.origin.demo.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author yutao
 * @create 2020-03-18 16:05
 **/

@RequestMapping("ThreadJoinDemo")
@RestController

public class ThreadJoinDemo {
    @GetMapping("test")
    public void test() throws InterruptedException {
        Thread thread = new Thread(() -> {
            System.out.println("task1");
        });
        Thread thread2 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("task2");
        });
        thread.start();
        thread2.start();

    }
}
